﻿//using FeatureManagement;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AutoMapper;
using Volo.Abp.Caching;
using Volo.Abp.Domain.Entities.Events.Distributed;
//using Volo.Abp.Features;
using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.ObjectExtending;
using Volo.Abp.ObjectExtending.Modularity;
using Volo.Abp.Threading;
using Xms.Abp.Data;
using Xms.Abp.Domain;
using Xms.Abp.ObjectMapping;

namespace MemberManagement;

[DependsOn(
    typeof(AbpMultiTenancyModule),
    typeof(MemberManagementDomainSharedModule),
    //typeof(FeatureManagementDomainModule),
    typeof(XmsAbpDataModule),
    typeof(XmsAbpDddDomainModule),
    typeof(XmsAbpObjectMappingModule),
    typeof(AbpCachingModule)
    )]
public class MemberManagementDomainModule : AbpModule
{
    private static readonly OneTimeRunner OneTimeRunner = new();

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddAutoMapperObjectMapper<MemberManagementDomainModule>();

        Configure<AbpAutoMapperOptions>(options =>
        {
            options.AddProfile<MemberManagementDomainMappingProfile>(validate: true);
        });

        Configure<AbpDistributedEntityEventOptions>(options =>
        {
            options.EtoMappings.Add<Member, MemberEto>();
        });

        //Configure<FeatureManagementOptions>(options =>
        //{
        //    options.Providers.Add<TenantFeatureManagementProvider>();
        //    options.ProviderPolicies[TenantFeatureValueProvider.ProviderName] = "TenantManagement.Tenants.ManageFeatures";
        //});
    }

    public override void PostConfigureServices(ServiceConfigurationContext context)
    {
        OneTimeRunner.Run(() =>
        {
            ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity(
                MemberManagementModuleExtensionConsts.ModuleName,
                MemberManagementModuleExtensionConsts.EntityNames.Member,
                typeof(Member)
            );
        });
    }
}
